package com.yztc.orangeentertainment.ui.main.subscribefragment;

import android.content.Context;
import android.util.Log;

import com.yztc.orangeentertainment.bean.subscribebean.ListBean;
import com.yztc.orangeentertainment.bean.subscribebean.SubscribeBean;
import com.yztc.orangeentertainment.config.SubscribeUrlConfig;
import com.yztc.orangeentertainment.http.SubscribeRetrofitService;

import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Subscriber;

/**
 * Created by My on 2016/10/5.
 */
public class SubModle implements SubContract.Modle {


    @Override
    public void getInterestAll(String type, Map<String, String> params, final OnLoadBottomListener loadBottomListener, Context context) {
        //获得网络数据
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(SubscribeUrlConfig.PATH.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Call<SubscribeBean> call=retrofit.create(SubscribeRetrofitService.class)
                .getSubTopAll(type,params);
        call.enqueue(new Callback<SubscribeBean>() {
            @Override
            public void onResponse(Call<SubscribeBean> call, Response<SubscribeBean> response) {
                if (response.isSuccessful()) {
                    List<ListBean> list = response.body().getData().getList();
                    loadBottomListener.onSuccess(list);
                } else {
                    Log.i("tag", "wrong");
                }
            }
            @Override
            public void onFailure(Call<SubscribeBean> call, Throwable t) {
                //获取数据失败
                loadBottomListener.onFailure((Exception) t);
            }
        });

    }

    @Override
    public void getInterestFromDb(Subscriber<List<ListBean>> subscriber) {

    }
}
